<?php
    include("comprobar.php");

if(isset($_GET['texto'])&&isset($_GET['campo'])){
    
        $link = mysql_connect('localhost', 'root', '')or die('No se pudo conectar: ' . mysql_error());
        mysql_select_db('bdproyecto') or die('No se pudo seleccionar la base de datos');
        mysql_set_charset('utf8',$link);
        $cod_usu=$_GET['codusu'];
        $query="SELECT cod_articulo,nombre,pvp,stock_prestamo 
        FROM articulo 
        WHERE ";
            if($_GET['campo']=='cod_articulo'){
                $query=$query.$_GET['campo']."=".$_GET['texto'];
            }
            else{
                $query=$query.$_GET['campo']." LIKE '%".$_GET['texto']."%'";
            }
        $result=mysql_query($query) or die ('Consulta fallida: ' . mysql_error());
        echo "<table id='tabdatos' sortable>\n";
        echo"<thead><th>Codigo<br>Producto</th><th>Titulo</th><th>Precio</th><th>Stock<br>Prestamo</th><th>Añadir</th></thead>";
        while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
            echo "<tr>";
            foreach ($line as $key=>$col_value) {
                if($key=='genero_l'){
                    echo "<td class='gen'>$col_value</td>";
                }
                else{
                    echo "<td>$col_value</td>";
                }
            }
            echo "<td><a href='nuevo_prestamo.php?cod-art=".$line['cod_articulo']."&cod-usu=".$cod_usu."'><img width='30' height='30' src='icons\add.png'></a></td>";
            echo "</tr>";
        }
        echo "</table>\n";
        
        mysql_free_result($result);
        mysql_close($link);

    
}
?>